package com.fmsz.xmly.adapters.findrecom;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fmsz.xmly.R;
import com.fmsz.xmly.activitys.findrecom.AlbumDetailActivity;
import com.fmsz.xmly.entitys.findrecom.FindRecomGuessEntity;
import com.fmsz.xmly.entitys.findrecom.GuessChildEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/6.
 */

public class FindRecomHotAdapter extends BaseAdapter {
    private List<GuessChildEntity> list;
    private Context context;
    private LayoutInflater inflater;

    public FindRecomHotAdapter(List<GuessChildEntity> list, Context context) {
        this.list = list;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FindRecomEditorAdapter.ViewHolder holder;
        if (convertView==null) {
            convertView=inflater.inflate(R.layout.find_recom_editor_item,parent,false);
            holder=new FindRecomEditorAdapter.ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder=(FindRecomEditorAdapter.ViewHolder)convertView.getTag();
        }
        GuessChildEntity entity = list.get(position);
        holder.trackTitle.setText(entity.getTrackTitle());
        holder.title.setText(entity.getTitle());
        final String albumId = entity.getAlbumId();
        String path=entity.getCoverMiddle();
        if (path!=null) {
            Picasso.with(context).load(path).into(holder.image);
            holder.image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(context,AlbumDetailActivity.class);
                    intent.putExtra("data",albumId);
                    context.startActivity(intent);
                }
            });
        }
        return convertView;
    }
    static  class ViewHolder{
        ImageView image;
        TextView trackTitle,title;
        public ViewHolder(View view){
            image=(ImageView)view.findViewById(R.id.find_recom_editor_item_iv);
            trackTitle=(TextView)view.findViewById(R.id.find_recom_editor_item_trackTitle);
            title=(TextView)view.findViewById(R.id.find_recom_editor_item_title);
        }
    }
}
